package com.loren.oauth.service;

import com.loren.oauth.data.dto.ApiUserInfo;
import com.loren.oauth.data.dto.UserAuthInfo;
import com.loren.oauth.utils.BeanConvertUtils;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;

import java.util.Collection;

public class SecurityUserInfo extends User {

    private static final long serialVersionUID = -791378776276312431L;

    private ApiUserInfo apiUserInfo;

    public SecurityUserInfo(String username, String password, Collection<? extends GrantedAuthority> authorities) {
        super(username, password, authorities);
    }

    public SecurityUserInfo(String username, String password, boolean enabled, boolean accountNonExpired, boolean credentialsNonExpired, boolean accountNonLocked, Collection<? extends GrantedAuthority> authorities) {
        super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
    }

    public SecurityUserInfo(String username, String password, boolean enabled, boolean accountNonExpired,
                            boolean credentialsNonExpired, boolean accountNonLocked, Collection<? extends GrantedAuthority> authorities, UserAuthInfo userAuthInfo) {
        super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
        this.apiUserInfo = BeanConvertUtils.sourceToTarget(userAuthInfo, ApiUserInfo.class);
    }

    public ApiUserInfo getApiUserInfo() {
        return apiUserInfo;
    }

}
